package in.muton.edushare.pages.user.panels;

import in.muton.edushare.pages.common.EdusharePanel;
import in.muton.edushare.pages.user.UserBase;
import in.muton.edushare.pages.user.UserCalendar;
import in.muton.edushare.pages.user.UserCourses;
import in.muton.edushare.pages.user.UserDept;
import in.muton.edushare.pages.user.UserFolders;
import in.muton.edushare.pages.user.UserPage;
import in.muton.edushare.panels.images.ImageWithLink;
import in.muton.edushare.url.EntityPageParams;
import in.muton.edushare.url.URLLoader;

import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import com.edushare.common.constants.ApplicationConstants;
import com.edushare.common.constants.URLConstants;
import com.edushare.common.vo.Users;

public class YourLeftMenuPanel extends EdusharePanel {
	
	private static final long serialVersionUID = 7604072436283832551L;
	private UserBase parentPage;
	protected static String[] menuItems = { 
		"UserUpdates", "UserFiles", "UserCalendar", 
		"UserDept", "UserCourses"};

	public YourLeftMenuPanel(String id, UserBase page) {
		super(id, page);
		this.parentPage = page;
		loadPanel();
	}

	private void loadPanel() {
		String highlight = this.getActivePage();
		add(new ImageWithLink("userImage", getModel(), ApplicationConstants.FILE_SUFFIX_VBADGE));
		add(new BookmarkablePageLink<Void>("profile", URLLoader.getPageClass(URLConstants.USER_PUBLIC_PAGE_SUMMARY),EntityPageParams.getParams(getModel())));
		for (String s : menuItems) {
			WebMarkupContainer wmc;
			add(wmc = new WebMarkupContainer(s));
			EntityPageParams.getParams(getModel(), s);
			if (highlight.compareTo(s) == 0) {
				wmc.add(new AttributeAppender("class", new Model<String>(
						"es-menuItemSelected"), " "));
			}
			if (s.equals("UserUpdates")) {
				wmc.add(new BookmarkablePageLink<Void>("link", UserPage.class,
						EntityPageParams.getParams(getModel())));
			} else if (s.equals("UserFiles")) {
				wmc.add(new BookmarkablePageLink<Void>("link", UserFolders.class,
						EntityPageParams.getParams(getModel())));
			} else if (s.equals("UserCalendar")) {
				wmc.add(new BookmarkablePageLink<Void>("link", UserCalendar.class,
						EntityPageParams.getParams(getModel())));
			} else if (s.equals("UserDept")) {
				wmc.add(new BookmarkablePageLink<Void>("link", UserDept.class,
						EntityPageParams.getParams(getModel())));
			} else if (s.equals("UserCourses")) {
				wmc.add(new BookmarkablePageLink<Void>("link",
						UserCourses.class, EntityPageParams
								.getParams(getModel())));
			} 
		}
	}

	private String getActivePage() {
		return parentPage.getActivePage();
	}

	private IModel<Users> getModel() {
		return parentPage.getModel();
	}

}
